# -*- coding: utf-8 -*-
import os

from django.core.management.base import BaseCommand
from django.conf import settings

from pygments.formatters import HtmlFormatter
from pygments.styles import get_all_styles

class Command(BaseCommand):
    help = "Generates pygments stylesheets, used for syntax highlighting"
    def handle(self, *args, **options):
        styles = list(get_all_styles())
        path = os.path.join(settings.MEDIA_ROOT, "css", "highlighting", "%s.css")
        for style in styles:
            f = file(path % style, "w+")
            f.write(HtmlFormatter(style=style).get_style_defs('.highlight'))
            f.close()
        print "generated stylesheets for %i pygments styles" % len(styles)